package com.wh1200.mybatis.xmlless.resolver

import com.wh1200.mybatis.xmlless.config.BaseResolverTest
import com.wh1200.xmlless.test.dao.StudentDAO
import com.wh1200.xmlless.test.model.Student
import org.junit.jupiter.api.DisplayName
import org.junit.jupiter.api.Test
import kotlin.reflect.jvm.javaMethod
import kotlin.test.assertContains
import kotlin.test.assertNotNull

/**
 *
 * @author 吴昊
 * @date 2023/12/12 11:30
 * @since v0.0.0
 * @version 1.0
 */
@DisplayName("测试Group By")
class GroupByQueryResolverTest : BaseResolverTest(StudentDAO::class.java) {

  @Test
  @DisplayName("解析通过注解添加额外的join，并从join的表中获取字段")
  fun resolveExtraJoins() {
    val q = createQueryForMethod(StudentDAO::findCountAndGradeGroupByGrade.javaMethod!!)
    val sql = q.sql
    assertNotNull(sql)
    assertContains(sql, "FROM")
    assertContains(sql, "GROUP BY")
    assertContains(sql, "count(*)")
  }

}
